package com.uchengwang.ui.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.Map;

/**
 * Created by U城网 on 2017/5/18.
 */

public class JsonUtils {

    private static JsonUtils manager;

    private JsonUtils(){}
    public static JsonUtils getManager() {
        if (manager == null){
            manager = new JsonUtils();
        }
        return manager;
    }

    /**
     * 将一个class或者List<class>解析成String
     * */
    public String beanToString(Object tClass){
        return JSON.toJSONString(tClass);
    }

    /**
     * 将一个bean String解析成bean class
     * */
    public <T>T stringToBean(String content, Class<T> c){
        return JSON.parseObject(content, c);
    }

    public String MapToString(Map map){
        return JSON.toJSONString(map);
    }

    /**
     * 将jsonString 转化为JSONObject
     * */
    public JSONObject getJSONObject(String con){
        return JSON.parseObject(con);
    }

    /**
     * 得到一个JSonObject
     * */
    public JSONObject getJSONObject(){
        return new JSONObject();
    }

    /**
     * json数组 转为list对象
     * */
    public <T>List<T> parseList(String data, Class<T> c){
        return JSON.parseArray(data, c);
    }


}
